﻿using Demo.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Demo
{
    public class MyDbContext: DbContext
    {
        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {

        }

        public DbSet<User> Users { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>()
                .HasKey(x=>x.Id)
                ;

            modelBuilder.Entity<UserProperty>()
                .HasKey(x => new {x.Key,x.UserId,x.Value })
                ;
            modelBuilder.Entity<UserTag>()
                .HasKey(x =>new { x.UserId,x.Tag })
                ;
            modelBuilder.Entity<BPFiles>()
                .HasKey(x => x.Id)
                ;

            base.OnModelCreating(modelBuilder);
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

            var loggerFactory = new LoggerFactory();
            loggerFactory.AddProvider(new EFLoggerProvider());
            // 一般输出的sql是@p 之类的，不会输出敏感信息，这里设置为true 就会 
            optionsBuilder.EnableSensitiveDataLogging(true);
            optionsBuilder.UseLoggerFactory(loggerFactory);





            base.OnConfiguring(optionsBuilder);
        }


    }
}
